package cn.itsource.wechat.controller;

import cn.itsource.basic.util.AjaxResult;
import cn.itsource.wechat.domain.BinderDto;
import cn.itsource.wechat.domain.WechartProperties;
import cn.itsource.wechat.service.IWeChatService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/wechat")
@Slf4j
public class WeChatController {

    @Autowired
    private IWeChatService weChatService;

    @Autowired
    private WechartProperties wechartProperties;

    /**
     * 重定向，跳转到扫码的页面
     */
    @GetMapping("/tologin")
    public String tologin(){

        return weChatService.tologin();
    }

    /**
     * 重定向，跳转到扫码的页面
     */
    @GetMapping("/callback")
    public String callback(String code){
        //业务层
        return weChatService.callback(code);
    }
    //绑定wxuser和user对象的接口
    @PostMapping("/binder")
    @ResponseBody //返回json格式
    public AjaxResult binder(@RequestBody BinderDto binderDto){
        //业务层
        return weChatService.binder(binderDto);
    }

    @RequestMapping("/test")
    public void test(){

        log.info("{}", wechartProperties);
        System.out.println(wechartProperties.getAppId());
        System.out.println(wechartProperties.getAppSecrect());
    }



}
